Julien is shopping
at a mall and he finds a CD that he wants
to buy.
Julien then checks his pocket to see if he has enough money to pay for the CD. Depending on money he will make a decision. Define
this.
if(my_money >
cost_of_CD)
then
buy_CD
else
get_a_job
end if;
Branching statement Example (Step 2)
Problem solving sequence:
1.Algorithm
2.Pseudo-code
3.Flowchat
4.C/C++ code
Note that the
pseudocode statement end if means "end the previous if
statement." This is to make it clear what statements are inside the if
statement and what statements are outside of the if statement.
Depending on a
certain condition a certain series of events will be executed. Another type
of branching statement is called a switch statement. A switch
statement is just a shorter way of writing a lot of if statements.
Switch statements will be explained a bit further.